//
//  BuyCell.swift
//  CompareBuying
//
//  Created by 唐先才 on 16/1/30.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class BuyCell: UITableViewCell {
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var mallLab: UILabel!
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var priceLab: UILabel!
    @IBOutlet weak var countLab: UILabel!
    var _model: TxcModel?
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func configCellWithModel(model: TxcModel) {
        _model = model
        guard let isGood = model.IsGood, iconImg = model.MainImage, name = model.MallName, time = model.InfoTime, title = model.InfoTitle, price = model.CommodityPrice else {
            print("BuyCell赋值失败")
            return
        }
        iconView.sd_setImageWithURL(NSURL(string: iconImg))
        mallLab.text = name + time
        titleLab.text = title
        priceLab.text = price
        countLab.text = isGood.stringValue
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    static func buyCellWith(tableView: UITableView, dataArray: NSMutableArray, indexPath: NSIndexPath) -> UITableViewCell {
        if let buyCell = tableView.dequeueReusableCellWithIdentifier("buyCell") as? BuyCell {
            if dataArray.count > 0 {
                if let model = dataArray[indexPath.row] as? TxcModel {
                    buyCell.configCellWithModel(model)
                }
            }
            return buyCell
        }
        return UITableViewCell()
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
